# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=dateutil
_pyname=python-dateutil
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-$_realname" "${MINGW_PACKAGE_PREFIX}-python3-$_realname")
pkgver=2.8.1
pkgrel=1
pkgdesc="Provides powerful extensions to the standard datetime module (mingw-w64)"
arch=('any')
license=('BSD' 'Apache')
url="https://github.com/dateutil/dateutil"
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python2-six"
             "${MINGW_PACKAGE_PREFIX}-python3-six")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest" 
              "${MINGW_PACKAGE_PREFIX}-python2-freezegun" 
              "${MINGW_PACKAGE_PREFIX}-python2-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest" 
              "${MINGW_PACKAGE_PREFIX}-python3-freezegun" 
              "${MINGW_PACKAGE_PREFIX}-python3-hypothesis")
source=("${_realname}-${pkgver}.tar.gz"::"https://files.pythonhosted.org/packages/source/${_pyname:0:1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"{,.asc})
validpgpkeys=("6B49ACBADCF6BD1CA20667ABCD54FCE3D964BEFB")
sha256sums=('73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c'
            '73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c')

prepare() {
  cd "${srcdir}"
 for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_pyname}-${pkgver}" "python${pver}-build-${CARCH}"
  done

}

build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
  for pver in {2,3}; do
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    if [ "${pver}" = "2" ]; then
      MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
        ${MINGW_PREFIX}/bin/pytest2 || warning "Tests failed"
    else
      MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
        ${MINGW_PREFIX}/bin/pytest || warning "Tests failed"
    fi 
  done
}


package_python3-dateutil() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-six")

  cd "${srcdir}/python3-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  local _py3basever=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
  chmod -R a+r $pkgdir/${MINGW_PREFIX}/lib/python${_py3basever}/

  # Remove data files
  #rm ${pkgdir}${MINGW_PREFIX}/lib/python${_py3basever}/site-packages/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz
}

package_python2-dateutil() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-six")

  cd "${srcdir}/python2-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  local _py2basever=$(${MINGW_PREFIX}/bin/python2 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  install -Dm644 LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
  chmod -R a+r ${pkgdir}/${MINGW_PREFIX}/lib/python${_py2basever}/

  # Remove data files
  #rm ${pkgdir}${MINGW_PREFIX}/lib/python${_py2basever}/site-packages/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz
}

package_mingw-w64-i686-python2-dateutil() {
  package_python2-dateutil
}

package_mingw-w64-i686-python3-dateutil() {
  package_python3-dateutil
}

package_mingw-w64-x86_64-python2-dateutil() {
  package_python2-dateutil
}

package_mingw-w64-x86_64-python3-dateutil() {
  package_python3-dateutil
}
